package com.meijm.entity;

import com.alibaba.fastjson.JSON;
import com.meijm.MyProcessor;
import com.meijm.pipeline.BHSBPipeline;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.model.OOSpider;
import us.codecraft.webmagic.model.annotation.ExtractBy;
import us.codecraft.webmagic.model.annotation.HelpUrl;
import us.codecraft.webmagic.model.annotation.TargetUrl;
import us.codecraft.webmagic.pipeline.Pipeline;

import javax.management.JMException;
import java.io.IOException;
import java.util.List;

@TargetUrl("https://bh.sb/post/\\d+/")
@HelpUrl("https://bh.sb/post/category/main/page/\\d+/")
@Getter
@Setter
public class BoHaiShiBei {

	@ExtractBy("//h1[@class='article-title']/a/text()")
	private String title;

	@ExtractBy(value = "//article[@class='article-content']/p/text()",notNull = true)
	private List<String> imgTitle;

	@ExtractBy(value = "//article[@class='article-content']/p/img/@src",notNull = true)
	private List<String> imgSrc;

	public String toString(){
		return  JSON.toJSONString(this);
	}

	public static void main(String[] args) throws IOException, JMException {
		OOSpider.create(Site.me().setSleepTime(1000), BoHaiShiBei.class).
				addUrl("https://bh.sb/post/category/main/").
				addPipeline(new BHSBPipeline()).thread(1).run();

	}
}
